package com.spring.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.spring.dao.FenxiangMapper;
import com.spring.entity.Fenxiang;
import com.spring.entity.Meishi;
import com.spring.service.FenxiangService;
import com.spring.util.PageInfoUtil;
import com.spring.util.Request;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service("FenxiangService")
public class FenxiangServiceImpl implements FenxiangService {

    @Resource
    private FenxiangMapper dao;


    public List<Fenxiang> select() { return dao.select(null); }


    public List<Fenxiang> select(Fenxiang y) { return dao.select(y); }


    public Fenxiang find(Object id) { return dao.selectByPrimaryKey(id);}


    public Fenxiang findEntity(Fenxiang id) { return dao.selectOne(id); }

    @Override
    public List<Fenxiang> selectPage(Fenxiang obj, int page, int pageSize) {
        PageHelper.startPage(page, pageSize, true);
        List<Fenxiang> list = select(obj);
        PageInfo<Fenxiang> pageInfo = new PageInfo(list);
        PageInfoUtil pageInfoUtil = new PageInfoUtil(page);
        pageInfoUtil.setPageInfo(Request.getRequest(), pageInfo.getTotal(), pageSize);
        return list;
    }


    public List<Fenxiang> selectPageExample(Example obj, int page, int pageSize) {
        PageHelper.startPage(page, pageSize, true);
        List<Fenxiang> list = dao.selectByExample(obj);
        PageInfo<Fenxiang> pageInfo = new PageInfo(list);
        PageInfoUtil pageInfoUtil = new PageInfoUtil(page);
        pageInfoUtil.setPageInfo(Request.getRequest(), pageInfo.getTotal(), pageSize);
        return list;
    }


    public int delete(Object id) { return dao.deleteByPrimaryKey(id); }


    public int insert(Fenxiang y) { return dao.insertSelective(y); }


    public int update(Fenxiang y) { return dao.updateByPrimaryKeySelective(y); }
}
